// service/yhq/yhq.js
const app = getApp()
import http from "../../utils/http"
import util from "../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabList:['审核中','等待展示','展示中','已结束','审核拒绝'],
    list:[],
    finish: false,
    loading: false,
    page: 1,
    active: 0
  },
  onChange(e){
    this.setData({
      active: e.detail.index
    })
    this.reload()
  },
  edit(e){
    util.skip('/service/issueYhq/issueYhq?id='+e.currentTarget.dataset.id)
  },

  //跳转发布优惠券
  toissueYhq(){
    wx.navigateTo({
      url: '../issueYhq/issueYhq',
    })
  },
  reload(){
    this.setData({
      list: [],
      page: 1,
      finish: false
    })
    this.getList()
  },
  more(){
    this.setData({
      page: ++this.data.page
    })
    this.getList()
  },
  getList(){
    if(this.data.finish){
      return 
    }
    if(this.data.loading){
      return 
    }
    this.setData({
      loading: true
    })
    let data = {
      page: this.data.page,
    }
    if(this.data.active == 0){
      data['is_check'] = 0
    }else if(this.data.active == 1){
      data['timttype'] = 0
      data['is_check'] = 1
    }else if(this.data.active == 2){
      data['timttype'] = 1
      data['is_check'] = 1
    }else if(this.data.active == 3){
      data['timttype'] = 2
      data['is_check'] = 1
    }else if(this.data.active == 4){
      data['is_check'] = -1
    }
    http.get('shop/shopcoupon', data).then(res => {
      if(res.data.length === 0){
        this.setData({
          finish: true
        })
      }
      let arr = this.data.list.concat(res.data)
      this.setData({
        list: arr
      })
      
    }).finally(res => {
      this.setData({
        loading: false
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.reload()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})